package com.ash.android_adk_demo

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.ash.base.bean.Schemes

class SubAdapter(
    private val subItems: MutableList<Schemes>,
    private var mOnItemClickLitener: ParentAdapter.OnItemClickLitener? = null
) : RecyclerView.Adapter<SubAdapter.SubViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SubViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_sub, parent, false)
        return SubViewHolder(view)
    }

    override fun onBindViewHolder(holder: SubViewHolder, position: Int) {
        holder.itemView.setOnClickListener {
            mOnItemClickLitener?.onItemClick(it,subItems[position])
        }
        holder.bind(subItems[position])
    }

    override fun getItemCount()= subItems.size


    inner class SubViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        private val schemeText: TextView = itemView.findViewById(R.id.subTvName)

        fun bind(scheme: Schemes) {
           schemeText.text = scheme.schemeName
        }
    }
}